
package com.market.web.action;

import java.util.List;

import org.springframework.beans.BeanUtils;

import com.market.bean.Message;
import com.market.constant.Constant;
import com.market.web.form.MessageForm;
import com.market.web.form.MsgSearchForm;
import com.market.web.tag.Pages;
import com.market.web.utils.ListUtils;

public class MsgSearchAction extends MessageAction
{
    private String type = "";

    private String category = "";

    private String subject = "";

    private String orderBy = "";

    public String getCategory()
    {
        return category;
    }

    public void setCategory(String category)
    {
        this.category = category;
    }

    public String getOrderBy()
    {
        return orderBy;
    }

    public void setOrderBy(String orderBy)
    {
        this.orderBy = orderBy;
    }

    public String getSubject()
    {
        return subject;
    }

    public void setSubject(String subject)
    {
        this.subject = subject;
    }

    public String getType()
    {
        return type;
    }

    public void setType(String type)
    {
        this.type = type;
    }
    
    public String execute() throws Exception
    {
        MsgSearchForm msf = new MsgSearchForm();
        BeanUtils.copyProperties(this, msf);
        int curp = getCurPage();
        List msg = getMessageService().findBySearchForm(msf, (curp - 1) * Constant.perPageMessage,
                Constant.perPageMessage);
        getRequest().setAttribute("news", setCategory(ListUtils.convert(msg, Message.class, MessageForm.class)));

        int count = getMessageService().getCountBySearchForm(msf);
        StringBuffer path = new StringBuffer();
        path.append(getRequest().getServletPath()).append(".do?type=").append(msf.getType()).append("&subject=").append(
                msf.getSubject()).append("&category=").append(msf.getCategory()).append("&orderBy=").append(
                msf.getOrderBy());
        Pages pages = new Pages();
        pages.setCurPage(curp);
        pages.setPerPage(Constant.perPageMessage);
        pages.setRowCount(count);
        pages.setPath(path.toString());
        getRequest().setAttribute(Constant.PAGES, pages);
        return SUCCESS;
        //return mapping.findForward("msgList");
    }

}
